//
//  HEPersonHeadCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/12/14.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEPersonHeadCell.h"

@interface HEPersonHeadCell ()

@property (nonatomic, strong) UILabel *titleLb;
@property (nonatomic, strong) UIImageView *arrowView;
@property (nonatomic, strong) UIImageView *headView;

@end

@implementation HEPersonHeadCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.qmui_borderPosition = QMUIViewBorderPositionBottom;
        self.qmui_borderWidth = 1;
        self.qmui_borderColor = CSplitLineColor;
        [self initUI];
    }
    return self;
}

- (void)initUI {
     
    _titleLb = [UILabel new];
    _titleLb.text = @"-";
    _titleLb.font = DYFont(17);
    _titleLb.textColor = CNavLightBlackColor;
    _titleLb.numberOfLines = 0;
    [self.contentView addSubview:_titleLb];
     
    _arrowView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 8, 12)];
    _arrowView.contentMode = UIViewContentModeScaleAspectFill;
    _arrowView.image = IMAGE_NAMED(@"go_gray");
    [self.contentView addSubview:_arrowView];
    self.accessoryView = _arrowView;
    
    // 头像
    UserInfo *user = [UserManager sharedUserManager].curUserInfo;
    UIImageView *userIcon = [UIImageView new];
    userIcon.contentMode = UIViewContentModeScaleAspectFill;
    userIcon.layer.masksToBounds = YES;
    userIcon.layer.cornerRadius = 20;
    [self.contentView addSubview:userIcon];
    _headView = userIcon;
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(15);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(userIcon.mas_left).mas_offset(-10);
        make.bottom.equalTo(self.contentView).mas_offset(-15);
    }];
   
    [userIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(self.contentView).mas_offset(-15);
        make.width.mas_offset(40);
        make.height.mas_offset(40);
        make.bottom.equalTo(self.contentView).mas_offset(-15);
    }];
}

- (void)refreshContent:(GDFiterCellModel *)fiterModel formModel:(GDFormModel *)formModel indexPath:(NSIndexPath *)indexPath {
    _titleLb.text = fiterModel.leftTitle; 
    [_headView sd_setImageWithURL:[NSURL URLWithString:formModel.pi_userIco] placeholderImage:IMAGE_NAMED(@"defualt_icon")];
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    NSString *text = [textField.text stringByReplacingCharactersInRange:range withString:string];
    [self.formModel setValue:text forKey:self.fiterModel.tableKey]; // 将textField中的值赋给_formModel
    return YES;
}
 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
